package com.joysuch.wwyt.edu.service.impl;

import com.joysuch.wwyt.edu.bean.EduCourseLearnHistoryDto;
import com.joysuch.wwyt.edu.entity.EduCourseLearnHistory;
import com.joysuch.wwyt.edu.mapper.EduCourseLearnHistoryMapper;
import com.joysuch.wwyt.edu.repository.EduCourseLearnHistoryDao;
import com.joysuch.wwyt.edu.service.EduCourseLearnHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xsx
 * @version 1.0
 * @date 2022/9/5 16:43
 */
@Service
public class EduCourseLearnHistoryServiceImpl implements EduCourseLearnHistoryService {

    @Autowired
    private EduCourseLearnHistoryDao eduCourseLearnHistoryDao;
    @Autowired
    private EduCourseLearnHistoryMapper eduCourseLearnHistoryMapper;


    @Override
    public EduCourseLearnHistoryDto getProgress(Long id, Long currentUserId,Long trainingId) {
        EduCourseLearnHistoryDto dto=new EduCourseLearnHistoryDto(0,0,0);
//        EduCourseLearnHistory history = eduCourseLearnHistoryDao.findByCourseawareIdAndUserId(id, currentUserId);
        EduCourseLearnHistory history = eduCourseLearnHistoryMapper.findByCourseawareIdAndUserId(id,currentUserId,trainingId);
        if (history!=null){
            dto.setIsFinishRead(history.getState());
            dto.setLearnTime(history.getAppLearnTime());
            dto.setLastTime(history.getLastTime());
        }
        return dto;
    }
}
